package com.lagou.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lagou.config.SentinelHandlersClass;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 该类用于模拟，我们要使用共享的那些配置信息做一些事情
 */
@RestController
@RequestMapping("/config")
@RefreshScope
public class ConfigController {

    // 和取本地配置信息一样
    @Value("${lagou.message}")
    private String lagouMessage;
    @Value("${mysql.url}")
    private String mysqlUrl;

    /**
     * 访问   http://localhost:8081/config/viewconfig
     * 内存级别的配置信息，要想获取最新的配置信息，只能重启服务
     */
    @GetMapping("/viewconfig")
    @SentinelResource(value = "viewconfig",
            blockHandlerClass = SentinelHandlersClass.class, blockHandler = "handleException",
            fallbackClass = SentinelHandlersClass.class, fallback = "handleError")
    public String viewconfig() {
        return "lagouMessage==>" + lagouMessage + " mysqlUrl=>" + mysqlUrl;
    }
}
